package com.lovo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lovo.bean.Supplierproduct;
import com.lovo.mapper.SupplierproductMapper;
import com.lovo.service.ISupplierproductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lovo
 * @since 2022-09-17
 */
@Service
public class SupplierproductServiceImpl extends ServiceImpl<SupplierproductMapper, Supplierproduct> implements ISupplierproductService {

    @Autowired
    SupplierproductMapper supplierproductMapper;

    @Override
    public List<Supplierproduct> findAllProductBySupId(int supId) {
        QueryWrapper<Supplierproduct> qw = new QueryWrapper<>();
        qw.eq("fk_supplierId", supId);
        List<Supplierproduct> list = supplierproductMapper.selectList(qw);
        return list;
    }

    @Override
    public void delProduct(int supplierProductId) {
        supplierproductMapper.deleteById(supplierProductId);
    }

    @Override
    public void updateProductPriceById(Integer productId, Integer price) {
        Supplierproduct supplierproduct = supplierproductMapper.selectById(productId);
        supplierproduct.setPPrice(price);
        supplierproductMapper.updateById(supplierproduct);
    }


    @Override
    public void addProduct(Supplierproduct supplierproduct) {
        supplierproductMapper.insert(supplierproduct);

    }

    @Override
    public Supplierproduct findByName(String productName, Integer supId) {
        QueryWrapper<Supplierproduct> qw = new QueryWrapper<>();
        qw.eq("p_name", productName);
        qw.eq("fk_supplierId", supId);
        return supplierproductMapper.selectOne(qw);

    }

}
